<?php

chdir(dirname(__FILE__)."/../..");
$path = getcwd();
chdir("../");
$path3 = getcwd();
chdir(dirname(__FILE__));
#debug($path3 , $path2);
include_once $path3."/lib/core.class.php";



class Ctradeshows extends IPlugin 
{
    function Ctradeshows($parent = null)
    {
        IPlugin::IPlugin($parent);
        $this->tplfolder = dirname(__FILE__)."/tpl";
    }
    
    function getPluginTag() { return "tradeshows"; }
    function getPluginName() { return "tradeshows plugin"; }
    function getPluginVersion() { return "1.0.0"; }
    
    function getProperty($p = null)
    {
        if(null == $p)
        {
            return array("MenuBlockTitle", "MenuTitle");
        }
        $result = "";
        switch ($p)
        {
            case "MenuBlockTitle": { return "Trade Shows"; } break;
            case "MenuTitle" : { return "Trade Shows"; } break;
        };
        return $result;
    }
    
    // ----------------------------------------------------------------------------------
    // --- [ Handling all actions ] -----------------------------------------------------
    // ----------------------------------------------------------------------------------

    function doAction($params)
    {
        if(null != ($result = IPlugin::doAction($params)))
        {
            return $result;
        }
        
        $core = &getCoreInstance();
        $db = $core->getProperty("db");
         //debug($_GET,"get");  debug($_POST,"post");  debug($_SESSION, "session");
        
        if (isset($_POST[add]))
            $db->exec("insert into tradeshows values()");
        
        if (isset($_POST[submit]))
        {
        //debug($_FILES);   
            foreach ($_POST[text] as $k => $v)
            {
                if (isne($_POST[is_active][$k])) {$x="is_active='1'";} else {$x="is_active='0'";}
                
                $x.=", `text`='".str2db($v)."'"; 
                $x.=", date='".$_POST[date][$k]."'"; 
                
                $sql = "update tradeshows set $x where id=$k";
                //debug($sql);
                $db->exec($sql);

            }
            
        }
                
        if ($_GET[del]>0)
            $db->exec("delete from tradeshows where id=$_GET[del]");
        
        
        return true;
    }


    // ----------------------------------------------------------------------------------
    // --- [ Render pages ] -------------------------------------------------------------
    // ----------------------------------------------------------------------------------

    function Render($params)
    {
        global $_G;
        if(null != ($result = IPlugin::Render($params)))
        {
            return $result;
        }
        
        $core = &getCoreInstance();
        $db = $core->getProperty("db");
        $framework = $core->getProperty("framework");
        $render = $framework->smarty;

        $page = "";

        switch ($_G["page"]) {
            default:
                $page = $this->render_tradeshows($core, $render, $db);
                break;
        }

        return $render->fetch("file:".$this->tplfolder."/".$page);
    }
    


    function render_tradeshows(&$core, &$render, &$db)
    {
        
        $tradeshows = $db->getall("select * from tradeshows");
        //debug($public_relations);
        $render->assign("tradeshows", $tradeshows);
        
        return "tradeshows.tpl.php";
    }
    
    
};


?>